package com.clear.honghefinance.admin.controller;

import com.clear.honghefinance.biz.modules.account.domain.dto.*;
import com.clear.honghefinance.biz.modules.account.domain.vo.GetAccountBookDetailVO;
import com.clear.honghefinance.biz.modules.account.domain.vo.ListAccountBookVO;
import com.clear.honghefinance.biz.modules.account.service.IAccountBookService;
import com.clear.honghefinance.common.dto.entity.ApiResponse;
import com.clear.honghefinance.common.dto.entity.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@Api(tags = "账套管理模块")
@RestController
@RequestMapping("/account_book")
@Slf4j
@RequiredArgsConstructor
public class AccountBookController {

    private final IAccountBookService accountBookService;

    /**
     * 创建账套
     *
     * @param dto req
     * @return
     */
    @ApiOperation(value = "创建账套")
    @PostMapping(value = "/add")
    public ApiResponse<Boolean> add(@Validated @RequestBody AddAccountBookDTO dto) {
        return ApiResponse.success(accountBookService.add(dto));
    }

    /**
     * 编辑、修改账套
     *
     * @param dto req
     * @return
     */
    @ApiOperation(value = "编辑账套")
    @PostMapping(value = "/update")
    public ApiResponse<Boolean> update(@Validated @RequestBody UpdateAccountBookDTO dto) {
        return ApiResponse.success(accountBookService.update(dto));
    }

    /**
     * 禁用启用账套
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "禁用启用账套")
    @PostMapping(value = "/disable")
    public ApiResponse<Boolean> disable(@Validated @RequestBody UpdateAccountBookStateDTO dto) {
        return ApiResponse.success(accountBookService.updateDisable(dto));
    }


    /**
     * 删除账套
     *
     * @param dto req
     * @return
     */
    @ApiOperation(value = "删除账套")
    @PostMapping(value = "/del")
    public ApiResponse<Boolean> del(@Validated @RequestBody DeleteAccountBookDTO dto) {
        return ApiResponse.success(accountBookService.delete(dto));
    }


    /**
     * 查询账套列表
     *
     * @param dto req
     * @return
     */
    @ApiOperation(value = "查询账套列表")
    @GetMapping(value = "/list")
    public ApiResponse<PageResult<ListAccountBookVO>> list(@Validated @ModelAttribute ListAccountBookDTO dto) {
        return ApiResponse.success(accountBookService.list(dto));
    }


    /**
     * 查询账套列表
     *
     * @param id 账套id
     * @return
     */
    @ApiOperation(value = "获取账套详情")
    @GetMapping(value = "/get")
    public ApiResponse<GetAccountBookDetailVO> get(@Validated @NotNull(message = "账套id不能为空")
                                                   @Min(value = 1) @RequestParam long id) {
        return ApiResponse.success(accountBookService.getDetailById(id));
    }
}
